/*
 * Copyright © 2009 Perseus Project - Tufts University <http://www.perseus.tufts.edu>
 *
 * This file is part of UniCollatorPerseus.
 *
 * AlignmentPerseus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * AlignmentPerseus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with AlignmentPerseus.  If not, see <http://www.gnu.org/licenses/>.
 */

package eu.himeros.alignment;

/**
 * Aligner for Arrays of integers.
 *
 * @author Federico Boschetti <federico.boschetti.73@gmail.com>
 */
public class IntArrayAligner extends ObjectArrayAligner {
    protected int[][] alignedInts = null;

    /**
     * Default Constructor.
     */
    public IntArrayAligner() {}

    /**
     * Perform the alignment.
     *
     * @param ints1 first int array.
     * @param ints2 second int array.
     * @return the aligned arrays.
     */
    public int[][] align(int[] ints1, int[] ints2) {
        Integer[] intObjs1 = new Integer[ints1.length];
        Integer[] intObjs2 = new Integer[ints2.length];
        for (int i = 0; i < ints1.length; i++) {
            intObjs1[i] = new Integer(ints1[i]);
        }
        for (int i = 0; i < ints2.length; i++) {
            intObjs2[i] = new Integer(ints2[i]);
        }
        Object[][] resObj = (Object[][]) align(intObjs1, intObjs2);
        alignedInts = new int[resObj.length][resObj[0].length];
        for (int i = 0; i < resObj.length; i++) {
            for (int j = 0; j < resObj[0].length; j++) {
                if (resObj[i][resObj[0].length - 1 - j] == null) {
                    alignedInts[i][j] = Integer.MIN_VALUE;
                } else {
                    alignedInts[i][j] = Integer.parseInt(resObj[i][resObj[0].length - 1 - j].toString());
                }
            }
        }
        return alignedInts;
    }

}
